<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$store=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->store_id));
	if($_SESSION['storeurl']){
		$storeurl=$_SESSION['storeurl'].'issale=1&id='.$store['id'].'&workerid='.$this->workerid;
	}else{
		$storeurl='/store.detail//issale=1&id='.$store['id'].'&workerid='.$this->workerid;
	}
	$store['url']=custom_url($storeurl,true);
	if($_SESSION['wxapp_id']){
		$image='oss/'.$_SESSION['uniacid'].'/images/jy_weishop/store/wxappid'.$store['id'].'_'.$this->workerid.'.jpg';
		$isadd=cfc('files')->source_check($image);
		if(!$isadd){
			$url=wxapp_links($storeurl);
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
			if($_SESSION['fromh5wxapp']){
				$url=$storeurl;
				$url='/pages/index/index?url='.urlencode($url);
			}
			$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
			$path='oss/'.$_SESSION['uniacid'].'/images/jy_weishop/store';
			if(!file_exists(ROOT_AT.$path)){
				mkdir(ROOT_AT.$path,0700, true);
			}
			cfc('files')->source_save($res,'nochoose','png','二维码',$image,'',$url);
		}
		$store['qrcode']=$image;
	}
	$store['desc'] = strip_tags(str_replace('&nbsp;','',$store['desc']));
	$store['desc'] = $store['desc'] ?cfc('tools')->substr($store['desc'],0,108):'';
	$return['isopenvoice']=$store['isopenvoice'];
	$return['store']=$store;
	$avatar=pdo_getcolumn('core_members',array('id'=>$return['item']['mid']),'avatar');
	$return['store']['logo']=$return['store']['logo']?$return['store']['logo']:$avatar;
	$return['status1']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id,'status'=>1,'deleted'=>0,'userdeleted'=>0));
	$return['status2']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id,'status'=>2,'deleted'=>0,'userdeleted'=>0));
	$return['status0']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id,'status'=>0,'deleted'=>0,'userdeleted'=>0));
    $return['status4']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id,'status'=>array(5),'deleted'=>0,'userdeleted'=>0));
	$return['goodsnum']=pdo_count('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>0),'id');
	$return['verifygoodsnum']=pdo_count('jy_weishop_verifygoods_log',array('uniacid'=>$_SESSION['uniacid'],'salerid'=>$_SESSION['uid']),'id');
	$return['verifynum']=pdo_count('jy_weishop_order_verify',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid']),'id');
	$return['selfverifynum']=pdo_count('jy_weishop_order_self',array('uniacid'=>$_SESSION['uniacid'],'clerk_id'=>$_SESSION['uid']),'id');
	if($perms_mobile){
		$check=strexists($perms_mobile,';jy_weishop/store.manage.order/;');
		if(!$check){
			$return['nocheck_order']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/store.manage.goods/;');
		if(!$check){
			$return['nocheck_goods']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/store.manage.store/;');
		if(!$check){
			$return['nocheck_store']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/store.manage.count/;');
		if(!$check){
			$return['nocheck_count']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/verify.index/;');
		if(!$check){
			$return['nocheck_verifyindex']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/verify.verifygoods/;');
		if(!$check){
			$return['nocheck_verifygoods']=true;
		}
		$check=strexists($perms_mobile,';jy_weishop/verify.selfindex/;');
		if(!$check){
			$return['nocheck_selfindex']=true;
		}
	}
	//获取小程序订阅消息ID	
	$tmplIds=array();
	$return['tmplIds']=$tmplIds;
	set_html('title','门店管理');
	exi($return);
}
if($_RQ['op']=='openvoice'){
	$post=get_postdata();
	$isopenvoice=intval($_RQ['isopenvoice']);
	pdo_update('jy_weishop_store',array('isopenvoice'=>$isopenvoice),array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->store_id));
	exi('设置成功！');	
}
//获取小程序订阅消息ID
if($_RQ['op']=='get_tmpids'){
	$tmplIds=array();
	$tmpid=cfc('wxapp_api')->get_tpl_template_id('30808',[6,1,3,4],'pay2seller','订单支付成功通知卖方','jy_weishop');
	if($tmpid){
		$tmplIds[]=$tmpid;
	}
	$tmpid=cfc('wxapp_api')->get_tpl_template_id('31042',[1,2,4,10,7],'receive2buyer','订单确认收货通知','jy_weishop');
	if($tmpid){
		$tmplIds[]=$tmpid;
	}
	$res['list']=$tmplIds;
	exi($res);
}